<?php

namespace app\workwechart\Work\Student;

use EasyWeChat\Kernel\BaseClient;

/**
 * Class Client.
 *
 * @author mingyoung <mingyoungcheung@gmail.com>
 */
class Client extends BaseClient
{
    public function test()
    {
        return "This is Test!";
    }

    /**
     * Create a user.
     *
     * @param array $data
     *
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
     *
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function create_student(array $data)
    {
        return $this->httpPostJson('cgi-bin/school/user/create_student', $data);
    }

    /**
     * Update an exist user.
     *
     * @param string $student_userid
     * @param array  $data
     *
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
     *
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function update_student(string $student_userid, array $data)
    {
        return $this->httpPostJson('cgi-bin/school/user/update_student', array_merge(['student_userid' => $student_userid], $data));
    }

    /**
     * Delete a user.
     *
     * @param string|array $userId
     *
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
     *
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function delete_student($userId)
    {
        if (is_array($userId)) {
            return $this->batch_delete_student($userId);
        }

        return $this->httpGet('cgi-bin/school/user/delete', ['userid' => $userId]);
    }

    /**
     * Batch delete users.
     *
     * @param array $useridlist
     *
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
     *
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function batch_delete_student(array $useridlist)
    {
        return $this->httpPostJson('cgi-bin/school/user/batch_delete_student', ['useridlist' => $useridlist]);
    }

    /**
     * Batch delete users.
     *
     * @param array $students
     *
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
     *
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function batch_create_student(array $students)
    {
        return $this->httpPostJson('cgi-bin/school/user/batch_create_student', ['students' => $students]);
    }

    /**
     * Batch update users.
     *
     * @param array $students
     *
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
     *
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function batch_update_student(array $students)
    {
        return $this->httpPostJson('cgi-bin/school/user/batch_update_student', ['students' => $students]);
    }

    /**
     * Create a parents.
     *
     * @param array $data
     *
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
     *
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function create_parent(string $parent_userid,string $mobile,bool $to_invite=false, array $children)
    {
        return $this->httpPostJson('cgi-bin/school/user/create_parent', [
            "parent_userid"=>$parent_userid,
            "mobile"=>$mobile,
            "to_invite"=>$to_invite,
            "children"=>$children,
        ]);
    }

    /**
     * Update an exist parents.
     *
     * @param string $parent_userid
     * @param array  $data
     *
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
     *
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function update_parent(string $parent_userid,string $new_parent_userid,string $mobile,bool $to_invite=false, array $children)
    {
        return $this->httpPostJson('cgi-bin/school/user/create_parent', [
            "parent_userid"=>$parent_userid,
            "new_parent_userid"=>$new_parent_userid,
            "mobile"=>$mobile,
            "to_invite"=>$to_invite,
            "children"=>$children,
        ]);    
    }

    /**
     * Delete a parents.
     *
     * @param string|array $parent_userid
     *
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
     *
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function delete_parent($parent_userid)
    {
        if (is_array($parent_userid)) {
            return $this->batch_delete_parent($parent_userid);
        }

        return $this->httpGet('cgi-bin/school/user/delete_parent', ['userid' => $parent_userid]);
    }

    /**
     * Batch delete parents.
     *
     * @param array $useridlist
     *
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
     *
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function batch_delete_parent(array $useridlist)
    {
        return $this->httpPostJson('cgi-bin/school/user/batch_delete_parent', ['useridlist' => $useridlist]);
    }

    /**
     * Batch create parents.
     *
     * @param array $parents
     *
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
     *
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function batch_create_parent(array $parents)
    {
        return $this->httpPostJson('cgi-bin/school/user/batch_create_parent', ['parents' => $parents]);
    }

    /**
     * Batch update parents.
     *
     * @param array $parents
     *
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
     *
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function batch_update_parent(array $parents)
    {
        return $this->httpPostJson('cgi-bin/school/user/batch_update_parent', ['parents' => $parents]);
    }
    /**
     * Get student or parent.
     *
     * @param string $userId
     *
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
     *
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     */
    public function get(string $userId)
    {
        return $this->httpGet('cgi-bin/school/user/get', ['userid' => $userId]);
    }
 
    /**
     * Get user list.
     *
     * @param int  $departmentId
     * @param bool $fetchChild
     *
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
     *
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     */
    public function getDetailedDepartmentUsers(int $departmentId, bool $fetchChild = false)
    {
        $params = [
            'department_id' => $departmentId,
            'fetch_child' => (int) $fetchChild,
        ];

        return $this->httpGet('cgi-bin/school/user/list', $params);
    }

    /**
     * @param string $mode //家校通讯录同步模式：1-禁止将标签同步至家校通讯录，2-禁止将家校通讯录同步至标签，3-禁止家校通讯录和标签相互同步
     *
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
     *
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     */
    public function set_arch_sync_mode(string $mode)
    {
        return $this->httpPostJson('cgi-bin/school/user/set_arch_sync_mode', ['arch_sync_mode' =>$mode]);
    }
}
